package com.ihelp.rest.mis.platform.controller;

import java.io.FileInputStream;
import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileUploadException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import com.ihelp.rest.mis.platform.service.UserTimeService;
import com.ihelp.rest.utils.HtmlUtil;
import com.ihelp.rest.utils.SessionUtils;

/**
 * 上网时长
*      
* 类名称：UserTimeController   
* 类描述：     
* 创建时间：2013-4-1 上午09:51:35    
* 备注：   
* @version
 */
@Controller
@RequestMapping("/usertime")
public class UserTimeController {

	@Autowired
	private UserTimeService service;
	
	/**
	 * 加载上网时长主页面
	 * @param request
	 * @return
	 */
	@RequestMapping("loadUsertimePage.do")
	public String loadUsertimePage(HttpServletRequest request){
		return "system/usertime/usertime";
	}
	
	/**
	 * 上网时长列表数据查询
	 * @param response
	 * @param page
	 * @param rows
	 */
	@RequestMapping("findUsertime.do")
	public void findUsertime(HttpServletResponse response, int page, int rows){
		String json = this.service.findUsertime(page, rows);
		HtmlUtil.writerJson(response, json);
	}
	
	@RequestMapping("saveUserTime.do")
	public void saveRecords(HttpServletResponse response,HttpServletRequest request, MultipartFile userFilePath) throws FileUploadException, IOException{
		FileInputStream file =  (FileInputStream)userFilePath.getInputStream();
		String result = this.service.saveUserTime(file, SessionUtils.getUser(request));
		HtmlUtil.writerHtml(response,result);
	} 
	
	
	
}
